package DailyQuestions;

import java.util.Scanner;

public class Day29_2_2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int[] ary = new int[n];
            for (int i = 0; i < n; i++) {
                ary[i] = sc.nextInt();
            }
            System.out.println(getFirstUnFormedNum(ary));
        }
    }

    public static int getFirstUnFormedNum(int[] ary) {
        int min = Integer.MAX_VALUE;//记录最小和
        int max = 0;//记录最大和
        for (int i = 0; i < ary.length; i++) {
            max += ary[i];
            min = Math.min(min, ary[i]);
        }
        boolean[][] res = new boolean[ary.length][max + 1];
        for (int i = 0; i < ary.length; i++) {
            //初始化第一列
            res[i][0] = true;
        }
        res[0][ary[0]] = true;//初始化第一行，其他位置默认是false
        for (int i = 1; i < res.length; i++) {
            for (int j = 1; j < res[0].length; j++) {
                if (j - ary[i] < 0) {
                    //F(i,j)=F(i-1,j)
                    res[i][j] = res[i - 1][j];
                } else {
                    //F(i,j)=F(i-1,j)||F(i-1,j-ary[i])
                    res[i][j] = res[i - 1][j] || res[i - 1][j - ary[i]];
                }
            }
        }
        for (int i = min; i < res[0].length; i++) {
            if (!res[res.length - 1][i]) {
                return i;
            }
        }
        return res[0].length;
    }
}
